package org.jeecg.modules.doctor;

import com.aliyuncs.exceptions.ClientException;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.base.Strings;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.modules.dic.vo.GoodAtResVo;
import org.jeecg.common.modules.dic.entity.DicBeGoodAt;
import org.jeecg.common.modules.dic.entity.DicCity;
import org.jeecg.common.modules.dic.service.IDicBeGoodAtService;
import org.jeecg.common.modules.dic.service.IDicCityService;
import org.jeecg.common.modules.dic.vo.CityResVo;
import org.jeecg.common.modules.doctor.entity.*;
import org.jeecg.common.modules.doctor.service.*;
import org.jeecg.common.modules.doctor.vo.CertInfoReqVo;
import org.jeecg.common.modules.doctor.vo.DoctorReqVo;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.data.request.DoctorEditSaveReq;
import org.jeecg.modules.data.response.DoctorDetailRes;
import org.jeecg.modules.data.response.DoctorEditInfoRes;
import org.jeecg.modules.data.response.DoctorInfoRes;


import org.jeecg.modules.system.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.*;
/**
 * @Description: 医生表
 * @Author: jeecg-boot
 * @Date:   2020-08-19
 * @Version: V1.0
 */
@Api(tags="医生表")
@RestController
@RequestMapping("/doctor/doctor/")
@Slf4j
public class DoctorController extends JeecgController<Doctor, IDoctorService> {
	@Autowired
	private IDoctorService doctorService;

	@Autowired
	private IDoctorConfigService doctorConfigService;

	@Resource
	private IDoctorExtendService doctorExtendService;

	@Resource
	private IDicBeGoodAtService dicBeGoodAtService;

	@Resource
	private IDicCityService dicCityService;

	@Resource  //医生和助理的关系
	private IDoctorAssistantRelationService doctorAssistantRelationService;

	@Resource  //待添加的医生表
	private IDoctorTempService doctorTempService;

	@GetMapping(value = "test")
	public Result<?> test(@RequestParam(name="name") String name){
		String  respMessage = String.format("WX_SUB", "oRBzQs55RIQ6n_oDPBxtdmfhp3Ik","gh_ec5d4de0ed55",System.currentTimeMillis());
		return Result.ok(respMessage);
	}

	/**
	 * 分页列表查询
	 *
	 * @param doctor
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	@AutoLog(value = "inquiry_info-分页列表查询")
	@ApiOperation(value="inquiry_info-分页列表查询", notes="inquiry_info-分页列表查询")
	@GetMapping(value = "/list")
	public Result<?> queryPageList(Doctor doctor,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
		String name = req.getParameter("name");
		Integer certificationStatus;
		String status = req.getParameter("certificationStatus");
		if(status != null){
			certificationStatus = Integer.valueOf(status);
		}else{
			certificationStatus = -1;
		}
		log.info("查询当前页：--------------" );
		Page<DoctorReqVo> pageList = new Page<>(pageNo,pageSize);
		pageList = doctorService.queryDoctors(pageList,name,certificationStatus);
		log.info("查询当前页："+pageList.getCurrent());
		log.info("查询当前页数量："+pageList.getSize());
		log.info("查询结果数量："+pageList.getRecords().size());
		log.info("数据总数："+pageList.getTotal());
		log.info("--------------------------------into pageList-------------------------------"+pageList);
		return Result.ok(pageList);
	}
	/**
	 * 分页列表查询
	 *
	 * @param doctor
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	@AutoLog(value = "inquiry_info-分页列表查询")
	@ApiOperation(value="inquiry_info-分页列表查询", notes="inquir0【y_info-分页列表查询")
	@GetMapping(value = "/tcmDoctorList")
	public Result<?> tcmDoctorList(Doctor doctor,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
		String name = req.getParameter("name");
		Integer certificationStatus;
		String status = req.getParameter("certificationStatus");
		if(status != null){
			certificationStatus = Integer.valueOf(status);
		}else{
			certificationStatus = -1;
		}
		log.info("查询当前页：--------------" );
		Page<DoctorReqVo> pageList = new Page<>(pageNo,pageSize);
		pageList = doctorService.queryTcmDoctors(pageList,name,certificationStatus);
		log.info("查询当前页："+pageList.getCurrent());
		log.info("查询当前页数量："+pageList.getSize());
		log.info("查询结果数量："+pageList.getRecords().size());
		log.info("数据总数："+pageList.getTotal());
		log.info("--------------------------------into pageList-------------------------------"+pageList);
		return Result.ok(pageList);
	}
	/**
	 * 医生认证信息列表查询
	 *
	 * @param doctor
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	@AutoLog(value = "医生表-认证信息分页列表查询")
	@ApiOperation(value="医生表-认证信息分页列表查询", notes="医生表-认证信息分页列表查询")
	@GetMapping(value = "/certList")
	public Result<?> queryCertList(Doctor doctor,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req){

		//数据开始的记录数
		int dataStart = (pageNo - 1) * pageSize;
		Integer certificationStatus;
		String status = req.getParameter("certificationStatus");
		if(status != null){
			certificationStatus = Integer.valueOf(status);
		}else{
			certificationStatus = -1;
		}

		//获取查询的数据
		List<CertInfoReqVo> certInfoReqVos = doctorService.selectCertInfo(certificationStatus,dataStart,pageSize);

//		查询到的总数据数
		Integer count = doctorService.getCertCount(certificationStatus);

		//组合分页展示的数据
		ResultVo vo = this.initResultVo(certInfoReqVos,count,pageNo,pageSize);
		return Result.ok(vo);
	}


	/**
	 * 组合返回的信息
	 * @param reqVos
	 * @param pageNo
	 * @param pageSize
	 * @return
	 */
	private ResultVo initResultVo(List reqVos, Integer count,Integer pageNo, Integer pageSize){
		ResultVo vo = new ResultVo();
		double dCount    = Double.valueOf(count);       //查询的数据总条数
		double dPageSize = Double.valueOf(pageSize);    //每页显示的条数
		int pages = (int) Math.ceil(dCount / dPageSize);//页码数量

		vo.setCurrent(pageNo);
		vo.setHitCount(false);
		vo.setOptimizeCountSql(true);
		vo.setOrders(new ArrayList<>());
		vo.setRecords(reqVos);
		vo.setPages(pages);
		vo.setSearchCount(true);
		vo.setSize(pageSize);
		vo.setTotal(count);
		return vo;
	}


	/**
	 * 医生信息批量新增
	 */
	@GetMapping(value = "/addAll")
	public Result<?> addAll() {
		List<DoctorTemp> doctorTemps = doctorTempService.getAll();
		List res = new ArrayList();

		for (DoctorTemp doctorTemp: doctorTemps) {
			//【一】医生信息保存
			Doctor doctor = new Doctor();
			doctor.setName(doctorTemp.getName());
			doctor.setMobile(doctorTemp.getMobile());
			doctor.setHospital(doctorTemp.getHospital());
			doctor.setDepartment(0);
			doctor.setTitle(doctorTemp.getTitle());
			doctor.setSex(doctorTemp.getSex());
			doctor.setProvinceId(2);
			doctor.setCityId(52);
			doctor.setStatus(1);
			doctor.setCreateTime(new Date());
			doctor.setBusinessType(0);
			doctor.setCertificationStatus(0);
			doctorService.save(doctor);

			//【二】医生配置信息保存
			DoctorConfig doctorConfig = new DoctorConfig();
			doctorConfig.setDoctorId(doctor.getId());
			doctorConfig.setFreeMessageCount(5);
			doctorConfig.setTextMoney(BigDecimal.valueOf(5));
			doctorConfig.setVideoMoney(BigDecimal.valueOf(100));
			doctorConfigService.save(doctorConfig);

			//【三】医生扩展信息保存
			DoctorExtend doctorExtend = new DoctorExtend();
			doctorExtend.setDoctorId(doctor.getId());
			doctorExtendService.save(doctorExtend);

			res.add(doctor.getId());
		}
		return Result.ok(res);
	}

	/**
	 * 医生头像的更改
	 * 更改头像之前要将新生成表
	 */
	@GetMapping(value = "/editHead")
	public Result<?> editHead() {
		List<DoctorTemp> doctorTemps = doctorTempService.getAll();
		List res = new ArrayList();
		for (DoctorTemp doctorTemp: doctorTemps) {
			//更改医生的头像地址
			Doctor doctor = doctorService.getByName(doctorTemp.getName());
			String head = "http://resources.dyzh120.com"+doctorTemp.getHeadImg();
			doctor.setHeadImg(head);
			boolean r = doctorService.updateById(doctor);

			res.add(r);
		}
		return Result.ok(res);
	}

	/**
	 *   添加
	 *
	 * @param doctorVO
	 * @return
	 */
	@AutoLog(value = "医生表-添加")
	@ApiOperation(value="医生表-添加", notes="医生表-添加")
	@PostMapping(value = "/add")
	public Result<?> add(@RequestBody DoctorVO doctorVO) {
		Doctor doctor =new Doctor();
		List res = new ArrayList();
		String doctorId= UUID.randomUUID().toString().replace("-", "");
		doctor.setId(doctorId);
		doctor.setName(doctorVO.getName());
		doctor.setMobile(doctorVO.getMobile());
		doctor.setHospital(doctorVO.getHospital());
		doctor.setDepartment(doctorVO.getDepartment());
		doctor.setTitle(doctorVO.getTitle());
		doctor.setSex(1);
		doctor.setProvinceId(2);
		doctor.setHeadImg(doctorVO.getHeadImg());
		doctor.setHeadImgTcm(doctorVO.getHeadImg());
		doctor.setCityId(52);
		doctor.setStatus(1);
		doctor.setCreateTime(new Date());
		doctor.setBusinessType(0);
		doctor.setCertificationStatus(2);
		doctor.setIsDisplay(1);
		doctor.setMaster(doctorVO.getMaster());
		doctor.setShare(0);
		doctorService.save(doctor);

		//【二】医生配置信息保存.
		DoctorConfig doctorConfig = new DoctorConfig();
		doctorConfig.setDoctorId(doctorId);
		doctorConfig.setFreeMessageCount(5);
		doctorConfig.setTextMoney(null);
		doctorConfig.setVideoMoney(null);
		doctorConfigService.save(doctorConfig);

		//【三】医生扩展信息保存
		DoctorExtend doctorExtend = new DoctorExtend();
		doctorExtend.setDoctorId(doctorId);
		doctorExtend.setGood(doctorVO.getGood());
		doctorExtend.setIntroduction(doctorVO.getIntroduction());
		doctorExtend.setGoodDesc(doctorVO.getGoodDesc());
		doctorExtend.setIntroductionTitle(doctorVO.getIntroductionTitle());
		doctorExtendService.save(doctorExtend);
		return Result.ok("添加成功！");
	}

	/**
	 *  编辑
	 *
	 * @param doctor
	 * @return
	 */
	@AutoLog(value = "医生表-编辑")
	@ApiOperation(value="医生表-编辑", notes="医生表-编辑")
	@PutMapping(value = "/edit")
	public Result<?> edit(@RequestBody Doctor doctor) throws ClientException {
		boolean res = doctorService.updateById(doctor);

//		boolean sendRes = false;
//		int status = doctor.getCertificationStatus();  //管理员操作认证的结果
//		if(status == 2){        //已认证
//			DySmsHelper.sendSms("17083098006",new JSONObject(), DySmsEnum.DOCTOR_CERT_SUCCESS);
//		}else if(status == 3){  //认证失败
//			DySmsHelper.sendSms("17083098006",new JSONObject(), DySmsEnum.DOCTOR_CERT_FAIL);
//		}
		return Result.ok("认证成功");
	}


	/**
	 * 医生的显示、不显示处理
	 */
	@AutoLog(value = "医生表-编辑")
	@ApiOperation(value="医生表-编辑", notes="医生表-编辑")
	@PutMapping(value = "/display")
	public Result<?> display(@RequestBody HashMap<String, String> map){
		String id = map.get("id");
		String display = map.get("display");
		Integer is_display = Integer.valueOf(display);

		Doctor doctor = doctorService.getById(id);
		doctor.setIsDisplay(is_display);
		boolean res = doctorService.updateById(doctor);
		if(res){
			return Result.ok("操作成功");
		}else{
			return Result.ok("操作失败");
		}
	}

	/**
	 * 图文、视频问诊费用、分成比例、挂号分成比例信息获取
	 */
	@AutoLog(value = "医生表-编辑")
	@ApiOperation(value="医生表-编辑", notes="医生表-编辑")
	@GetMapping(value = "/getConfig")
	public Result<?> getConfig(@RequestParam(name="id",required=false ) String id){
		Doctor doctor = doctorService.getById(id);
		if(Objects.isNull(doctor)){
			return Result.error("该医生不存在！");
		}

		//医生问诊费用
		DoctorConfig doctorConfig = doctorConfigService.getByDoctorId(id,true);
		if(Objects.isNull(doctorConfig)){
			return Result.error("该医生暂无配置信息，请联系管理员！");
		}
		DoctorInfoRes doctorInfo = new DoctorInfoRes();
		doctorInfo.setId(id);
		doctorInfo.setShare(doctor.getShare());
		doctorInfo.setTextMoney(doctorConfig.getTextMoney());
		doctorInfo.setVideoMoney(doctorConfig.getVideoMoney());
		log.info("分成信息：{}",doctorInfo);

		//设置挂号分成比例
		int ratio = doctorConfig.getRegisterRatio() == null ? 0 : doctorConfig.getRegisterRatio();
		doctorInfo.setRegisterRatio(ratio);
		return Result.ok(doctorInfo);
	}

	/**
	 * 问诊费用、分成比例、挂号分成比例信息编辑
	 */
	@AutoLog(value = "医生表-编辑")
	@ApiOperation(value="医生表-编辑", notes="医生表-编辑")
	@PutMapping(value = "/configEdit")
	public Result<?> configEdit(@RequestBody DoctorEditSaveReq doctorEditSave){
		//【一】医生分成比例的编辑保存
		Doctor doctor = doctorService.getById(doctorEditSave.getId());
		doctor.setShare(doctorEditSave.getShare());
		boolean resShare = doctorService.updateById(doctor);

		//【二】医生问诊费用、挂号分成比例的编辑保存
		DoctorConfig doctorConfig = doctorConfigService.getByDoctorId(doctorEditSave.getId(),true);
		doctorConfig.setTextMoney(doctorEditSave.getTextMoney());
		doctorConfig.setVideoMoney(doctorEditSave.getVideoMoney());
		doctorConfig.setRegisterRatio(doctorEditSave.getRegisterRatio());
		boolean resInter = doctorConfigService.updateById(doctorConfig);

		if(resShare && !resInter){
			return Result.error("问诊费用、挂号分成比例保存失败！");
		}else if(!resShare && resInter){
			return Result.error("分成比例保存失败！");
		}else if(!resShare && !resInter){
			return Result.error("分成比例、问诊费用保存失败！");
		}
		return Result.ok("保存成功");
	}



	/**
	 * 医生信息编辑的查询
	 * @param id
	 * @return
	 */
	@AutoLog(value = "医生表-通过id查询")
	@ApiOperation(value="医生表-通过id查询", notes="医生表-通过id查询")
	@GetMapping(value = "/doctorEditInfo")
	public Result<?> editDoctorInfo(@RequestParam(name="id",required=false ) String id) {
		//处理医生信息
		Doctor doctor = doctorService.getById(id);
		if(doctor==null) {
			return Result.error("未找到对应数据");
		}

		DoctorEditInfoRes doctorEditInfo = new DoctorEditInfoRes();
		doctorEditInfo.setId(doctor.getId());
		doctorEditInfo.setName(doctor.getName());
		doctorEditInfo.setSex(doctor.getSex());
		doctorEditInfo.setIdCard(doctor.getIdcard());
		doctorEditInfo.setHospital(doctor.getHospital());
		doctorEditInfo.setMaster(doctor.getMaster());
		doctorEditInfo.setHeadImgTcm(doctor.getHeadImgTcm());

		//处理省、市信息
		if(doctor.getProvinceId() != null || doctor.getCityId() != null){
			DicCity dicProvince = dicCityService.getById(doctor.getProvinceId());
			doctorEditInfo.setProvinceName(dicProvince.getName());
			doctorEditInfo.setProvinceId(dicProvince.getId());
			DicCity dicCity = dicCityService.getById(doctor.getCityId());
			doctorEditInfo.setCityName(dicCity.getName());
			doctorEditInfo.setCityId(dicCity.getId());
		}else{
			doctorEditInfo.setProvinceName("");
			doctorEditInfo.setProvinceId(0);
			doctorEditInfo.setCityName("");
			doctorEditInfo.setCityId(0);
		}

		doctorEditInfo.setTitle(doctor.getTitle());

		//处理科室信息
		if(doctor.getDepartment() != null && doctor.getDepartment() != 0){
			DicBeGoodAt dicBeGoodAt = dicBeGoodAtService.getById(doctor.getDepartment());
			doctorEditInfo.setDepartmentName(dicBeGoodAt.getName());
			doctorEditInfo.setDepartmentId(dicBeGoodAt.getId());
		}else{
			doctorEditInfo.setDepartmentName("");
			doctorEditInfo.setDepartmentId(0);
		}

		//获取医生扩展信息
		DoctorExtend doctorExtend = doctorExtendService.getByDoctorId(id);
		doctorEditInfo.setGood(doctorExtend.getGood());
		doctorEditInfo.setIntroduction(doctorExtend.getIntroduction());
		doctorEditInfo.setGoodDesc(doctorExtend.getGoodDesc());
		doctorEditInfo.setIntroductionTitle(doctorExtend.getIntroductionTitle());
		return Result.ok(doctorEditInfo);
	}

	/**
	 * 所有科室的查询
	 * @return
	 */
	@AutoLog(value = "医生表-通过id查询")
	@ApiOperation(value="医生表-通过id查询", notes="医生表-通过id查询")
	@GetMapping(value = "/department")
	public Result<?> department() {
		//获取所有科室
		List<DicBeGoodAt> department = dicBeGoodAtService.getDicBeGoodInfo();
		return Result.ok(department);
	}

	/**
	 * 获取擅长的信息
	 * @return
	 */
	@AutoLog(value = "医生表-通过id查询")
	@ApiOperation(value="医生表-通过id查询", notes="医生表-通过id查询")
	@GetMapping(value = "/goodInfo")
	public Result<?> goodInfo() {
		//获取科室和擅长信息
		List<GoodAtResVo> goodInfo = dicBeGoodAtService.getGoodAll();
		return Result.ok(goodInfo);
	}

	/**
	 * 获取地址信息
	 * @return
	 */
	@AutoLog(value = "医生表-通过id查询")
	@ApiOperation(value="医生表-通过id查询", notes="医生表-通过id查询")
	@GetMapping(value = "/cityInfo")
	public Result<?> cityInfo() {
		//获取地址信息
		List<CityResVo> cityReqVos = dicCityService.getCityAll();
		return Result.ok(cityReqVos);
	}

	/**
	 * 医生信息编辑保存
	 * @return
	 */
	@AutoLog(value = "医生表-通过id查询")
	@ApiOperation(value="医生表-通过id查询", notes="医生表-通过id查询")
	@PutMapping(value = "/editSave")
	public Result<?> editSave(@RequestBody DoctorEditInfoRes doctorEditInfo){
		LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
		Date date = new Date();
		//【一】医生表信息编辑
		Doctor doctor = doctorService.getById(doctorEditInfo.getId());
		doctor.setId(doctorEditInfo.getId());
		doctor.setName(doctorEditInfo.getName());
		doctor.setSex(Integer.valueOf(doctorEditInfo.getSex()));
		doctor.setIdcard(doctorEditInfo.getIdCard());
		doctor.setHospital(doctorEditInfo.getHospital());
		doctor.setProvinceId(Integer.valueOf(doctorEditInfo.getProvinceId()));
		doctor.setCityId(Integer.valueOf(doctorEditInfo.getCityId()));
		doctor.setTitle(doctorEditInfo.getTitle());
		doctor.setDepartment(Integer.valueOf(doctorEditInfo.getDepartmentId()));
		doctor.setUpdateBy("admin");
		doctor.setUpdateTime(date);
		doctor.setMaster(doctorEditInfo.getMaster());

		boolean doctorRes = doctorService.updateById(doctor);
		if(!doctorRes){
			return Result.ok("医生信息保存失败！");
		}

		//【二】医生扩展表（擅长、介绍）编辑保存
		DoctorExtend doctorExtend = new DoctorExtend();
		DoctorExtend doctorExtendOne = doctorExtendService.getByDoctorId(doctorEditInfo.getId());

		doctorExtend.setId(doctorExtendOne.getId());
		doctorExtend.setDoctorId(doctorExtendOne.getDoctorId());
		doctorExtend.setGood(doctorEditInfo.getGood());
		doctorExtend.setGoodDesc(doctorEditInfo.getGoodDesc());
		doctorExtend.setIntroductionTitle(doctorEditInfo.getIntroductionTitle());
		doctorExtend.setIntroduction(doctorEditInfo.getIntroduction());
		boolean doctorExtendRes = doctorExtendService.updateById(doctorExtend);
		if(!doctorExtendRes){
			return Result.ok("医生擅长和介绍保存失败！");
		}
//		return Result.ok(doctorEditInfo);
		return Result.ok("保存成功！");
	}


	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "医生表-通过id删除")
	@ApiOperation(value="医生表-通过id删除", notes="医生表-通过id删除")
	@DeleteMapping(value = "/delete")
	public Result<?> delete(@RequestParam(name="id",required=false ) String id) {
		doctorService.removeById(id);
		return Result.ok("删除成功!");
	}

	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "医生表-批量删除")
	@ApiOperation(value="医生表-批量删除", notes="医生表-批量删除")
	@DeleteMapping(value = "/deleteBatch")
	public Result<?> deleteBatch(@RequestParam(name="ids",required=false ) String ids) {
		this.doctorService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.ok("批量删除成功!");
	}

	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "医生表-通过id查询")
	@ApiOperation(value="医生表-通过id查询", notes="医生表-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<?> queryById(@RequestParam(name="id",required=false ) String id) {
		Doctor doctor = doctorService.getById(id);
		if(doctor==null) {
			return Result.error("未找到对应数据");
		}
		return Result.ok(doctor);
	}
	/**
	 * 通过id查询医生和名下医助信息
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "医生表-通过id查询")
	@ApiOperation(value="医生表-通过id查询", notes="医生表-通过id查询")
	@GetMapping(value = "/queryAssistantInfo")
	public Result<?> queryAssistantInfo(@RequestParam(name="id",required=false  ) String id) {
		//1、医生信息
		Doctor doctor = doctorService.getById(id);
		if(Objects.isNull(doctor)){
			return Result.ok("该专家不存在");
		}

		//获取擅长信息
		DoctorExtend doctorExtend = doctorExtendService.getByDoctorId(doctor.getId());
		if(Objects.isNull(doctorExtend)){
			return Result.ok("该专家的擅长信息不存在");
		}

		//获取部门的名称
		String departName = "";
		if(doctor.getDepartment() != null && doctor.getDepartment() != 0){
			DicBeGoodAt dicBeGoodAt = dicBeGoodAtService.getById(doctor.getDepartment());
			departName = dicBeGoodAt.getName();
		}

		//获取省、市、县信息
		if(doctor.getProvinceId() == null || doctor.getProvinceId() == 0 ||
				doctor.getCityId() == null || doctor.getCityId() == 0){
			doctor.setProvinceId(2); //北京
			doctor.setCityId(52);    //北京
		}
		DicCity province = dicCityService.getById(doctor.getProvinceId());
		DicCity city = dicCityService.getById(doctor.getCityId());

		//组合医生详情
		DoctorDetailRes detail = new DoctorDetailRes();
		detail.setId(doctor.getId());
		detail.setName(doctor.getName());
		detail.setMobile(doctor.getMobile());
		detail.setMaster(doctor.getMaster());
		detail.setHospital(doctor.getHospital());
		detail.setDepartment(departName);
		detail.setGoodAt(doctorExtend.getGood());
		detail.setPlace(province.getName()+" "+city.getName());

		//2、医生的医助信息
		List<DoctorAssistantRelation> doctorAssistantRelations = doctorAssistantRelationService.queryByDoctorId(id);
		//组合医生和助理的信息
		List assistant = new ArrayList();
		if(doctorAssistantRelations.size() > 0){
			for(DoctorAssistantRelation val:doctorAssistantRelations ){
				Doctor doctorOne = doctorService.getById(val.getAssistantId());
				assistant.add(doctorOne);
			}
		}

		List response = new ArrayList();
		response.add(detail);
		response.add(assistant);
		return Result.ok(response);
	}

	/**
	 * 导出excel
	 *
	 * @param request
	 * @param doctor
	 */
	@RequestMapping(value = "/exportXls")
	public ModelAndView exportXls(HttpServletRequest request, Doctor doctor) {
		return super.exportXls(request, doctor, Doctor.class, "医生表");
	}

	/**
	 * 通过excel导入数据
	 *
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
	public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
		return super.importExcel(request, response, Doctor.class);
	}

}
